<?php
namespace app\admin\controller;
use think\Db;
class Pricecode extends SessionCheck{
    
    public function index(){
    //页面
     $where=[];
     $aid=request()->request("aid");
     if (!empty($aid)) {
            $where['aid'] = $aid;
        } 
     $pages = pages('type_price', $where, input('get.page'));    
     $data = Db::table('type_price')->where($where)->whereIn('aid', session('aid'))->limit($pages['limit'])->order('id desc')->select();   
     foreach($data as $k=>$v){
       if(!empty($v['aid'])){
          $area=Db::table("area")->where('id',$v['aid'])->value("name"); 
          $data[$k]['area']=$area; 
       }else{
           $data[$k]['area']="";//值为空
       }    
     }
     
     return view('', ['data' => $data, 'pages' => $pages['pages'], 'menu_list' => $this->menu_list]);   
    }
    
    public function edit(){
      $id=request()->request("id");  //要对其修改的id
      if(request()->isPost()){
         $post=request()->post();
         if($id){
           Db::table("type_price")->where(['id'=>$id])->update($post);   
          }
      }
      $data = Db::table('type_price')->where(['id'=>$id])->find();
      return view('',['data'=>$data,'menu_list' => $this->menu_list]);  
    }
    //删除
    public function del(){
        $id = request()->request('id');
        $page = request()->request('page');
        Db::table('type_price')->delete($id);
        $this->redirect(url('pricecode/index') . '?page=' . $page);  
 
    }
    
    
   //添加
   public function add(){
   //缺少数据安全验证
    $data=input('post.'); 
    if($data==""){
      echo "数据error";
    }
    Db::table("type_price")->insert($data);//插入数据
   return view('',['menu_list'=>$this->menu_list]);
   } 
}
